package com.demo.jpa.dao.entity;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * @Author:LiaoYouLe
 * @Date: Created in 2018/7/27
 * @Description
 * @Modifyied By:
 */
@Entity
@Table(name = "role")
@Getter
@Setter
@NamedEntityGraphs(
        @NamedEntityGraph(
                name = "RoleEntity.privileges",
                attributeNodes = {
                        @NamedAttributeNode("privileges")
                }

        )
)
public class RoleEntity {
    @Id
    private Integer rid;

    private String rname;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "role_pri",
            joinColumns = @JoinColumn(name = "r_p_rid", referencedColumnName = "rid"),
            inverseJoinColumns = @JoinColumn(name = "r_p_pid", referencedColumnName = "pid")

    )
    @OrderBy("pid desc")
    private List<PrivilegeEntity> privileges;

}
